﻿using System;
using System.Collections.Generic;
using System.Threading;
using ThrottledProcessing.SampleApplication.Domain;
using ThrottledProcessing.SampleApplication.Interfaces;
using ThrottledProcessing.SampleApplication.Messages;

namespace ThrottledProcessing.SampleApplication.Services
{
    public class BillPaymentService : IBillPaymentService
    {
        private readonly ILoggingService loggingService;

        public BillPaymentService(ILoggingService loggingService)
        {
            this.loggingService = loggingService;
        }

        public GetUpcomingBillsResponse GetUpcomingBills(GetUpcomingBillsRequest request)
        {
            loggingService.Debug(string.Format("Getting upcoming bills for userId: {0}", request.UserId));

            // Simulate latency
            Thread.Sleep(DateTime.Now.Millisecond*2);

            var bills = new List<Bill>();

            for (var i = 0; i < 5; i++)
            {
                bills.Add(new Bill
                              {
                                  Amount = i*10,
                                  DueDate = DateTime.Now.AddDays(i),
                                  Payee = "Payee " + i
                              });
            }

            return new GetUpcomingBillsResponse
                       {
                           UpcomingBills = bills
                       };
        }
    }
}